<html>
<head><meta charset="utf-8"><title>Declaring and Using Modules · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Declaring.20and.20Using.20Modules.html">Declaring and Using Modules</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="211696421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Declaring%20and%20Using%20Modules/near/211696421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edward Bebbington <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Declaring.20and.20Using.20Modules.html#211696421">(Sep 29 2020 at 23:10)</a>:</h4>
<p>Hello,</p>
<p>Not sure if this is the right place so feel free to delete if it isn't, but i was just looking for somewhere to ask for some help</p>
<p>I've started learning Rust (2 days ago..) but i'm already very familiar with programming, but i've been having problems trying to declare and use modules, what i have is:</p>
<div class="codehilite"><pre><span></span><code>// ./src/main.rs
#[path = &quot;server.rs&quot;]
mod server;
//mod response;
//mod request;

fn main () {
    let options = server::HttpOptions {
      hostname: String::from(&quot;0.0.0.0&quot;),
      port: 1334
    };
    server::listen(options)
}
</code></pre></div>


<div class="codehilite"><pre><span></span><code>// ./src/server.rs
use std::net::TcpListener;
use std::thread;
#[path = &quot;request.rs&quot;]
mod request;

pub struct HttpOptions {
  pub hostname: String,
  pub port: u32
}

pub fn listen(options: HttpOptions) {
        let port_str: String = options.port.to_string();
        let address = format!(&quot;{}:{}&quot;, options.hostname, port_str);
        let listener = TcpListener::bind(address).unwrap();

        for stream in listener.incoming() {
            let stream = stream.unwrap();

            println!(&quot;Connection established!&quot;);
            //handle_request(stream); single threaded
            thread::spawn(|| {  // multi threaded
                        request::handle_request(stream);
            });
        }
}
</code></pre></div>


<p>This works fine, but as soon as I place <code>HttpOptions</code> and <code>listen</code> inside a <code>mod server {</code>, i get errors:</p>
<div class="codehilite"><pre><span></span><code>error[E0433]: failed to resolve: use of undeclared type or module `thread`
  --&gt; src/server.rs:22:13
   |
22 |             thread::spawn(|| {  // multi threaded
   |             ^^^^^^ use of undeclared type or module `thread`

error[E0433]: failed to resolve: use of undeclared type or module `request`
  --&gt; src/server.rs:23:25
   |
23 |                         request::handle_request(stream);
   |                         ^^^^^^^ use of undeclared type or module `request`

error[E0433]: failed to resolve: use of undeclared type or module `TcpListener`
  --&gt; src/server.rs:15:24
   |
15 |         let listener = TcpListener::bind(address).unwrap();
   |                        ^^^^^^^^^^^ not found in this scope

error[E0422]: cannot find struct, variant or union type `HttpOptions` in module `server`
 --&gt; src/main.rs:7:27
  |
7 |     let options = server::HttpOptions {
  |                           ^^^^^^^^^^^ not found in `server`
  |
help: consider importing this struct
  |
1 | use crate::server::server::HttpOptions;
</code></pre></div>


<p>But i am already using the <code>std::&lt;...&gt;</code> packages, and none of my code is a crate</p>



<a name="211696489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Declaring%20and%20Using%20Modules/near/211696489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Declaring.20and.20Using.20Modules.html#211696489">(Sep 29 2020 at 23:11)</a>:</h4>
<p>this is better to ask in <a class="stream" data-stream-id="122651" href="/#narrow/stream/122651-general">#general</a> or <a href="http://users.rust-lang.org/">users.rust-lang.org/</a>, this stream is for working on the rust compiler itself</p>



<a name="211696602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Declaring%20and%20Using%20Modules/near/211696602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edward Bebbington <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Declaring.20and.20Using.20Modules.html#211696602">(Sep 29 2020 at 23:12)</a>:</h4>
<p>thanks <span class="user-mention" data-user-id="232545">@Joshua Nelson</span>, it isn't all too clear on where to ask</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>